<?php if (!defined("_ECRIRE_INC_VERSION")) return;
/**
 * Aloha Cart
 *
 * @author     Aleksey Yaroshchuk (aleksey.yaroshchuk@gmail.com)
 * @license    GNU/GPL
 * @package    plugins
 * @subpackage alohacart
 * @copyright  (c) Aleksey Yaroshchuk 2011-2012
 * @link       http://www.spip-contrib.net/AlohaCart
 */

include_spip('functions/pdk_common');
include_spip('functions/pdk_database');

function formulaires_alohacart_extension_charger_dist($id_extension){
	$valeurs = array();
    
    $extension_mdl = pdk_load_class('AlohacartExtensionModel','classes/');
	
    $valeurs = $extension_mdl->select_by_id($id_extension, true);
    
    $valeurs['template'] = strtolower($valeurs['type']).'/'.$valeurs['code'];
    
    $extension = $extension_mdl->GetExtensionClassByID($id_extension);
    
    $data = $extension->GetMetaData();
    
    foreach ($extension->fields as $field) {
        // Приставку 'extension_' используем потому что не получилось через saisies сделать имя инпута массивом. Если получится, то можно будет переделать
        $valeurs['extension_'.$field] = isset($data[$field])?$data[$field]:'';   
    }
	// We must provide free_from field by hand, because it may not be defined in $extension->fields array
	$valeurs['extension_free_from'] = isset($data['free_from']) ? $data['free_from'] : '';	
    
	$valeurs['extension_list'] = isset($data['list']) ? $data['list'] : '';	
	
    $valeurs['order_statuts'] = select_reference_to_array('spip_alohacart_orders_statuts', 'id_statut', 'titre', null, array(), array(), 'titre');
    foreach ($valeurs['order_statuts'] as &$titre) { $titre = supprimer_numero($titre); }
    
    $valeurs['currencies'] = select_reference_to_array('spip_ecatalogue_currencies', 'id_currency', 'titre', null, array(), array(), 'titre');
    foreach ($valeurs['currencies'] as &$titre) { $titre = supprimer_numero($titre); }
    
    //$valeurs['main_currency_id'] = $currency_mdl->GetMainCurrencyId();
    
    if ($valeurs['active']) $valeurs['active'] = 'on'; 
	
	return $valeurs;
}
